package com.dyc.caradvertisting.ui.fmt.tab.store;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.dyc.caradvertisting.R;
import com.dyc.caradvertisting.bean.req.Gooods;
import com.dyc.caradvertisting.comm.GsonUtils;
import com.dyc.caradvertisting.ui.fmt.tab.store.VH.GoodsVH;
import com.dyc.caradvertisting.widget.trView.TRecyclerView;
import com.njh.tools.base.BaseFragment;
import com.njh.tools.common.userInfo.SPUserInfo;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link GoodsFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class GoodsFragment extends BaseFragment<GoodsPresenter, GoodsModel> implements GoodsContract.View {
    private static final String ARG_PARAM1 = "param1";
    @BindView(R.id.tr_content)
    TRecyclerView trContent;

    private String mParam1;


    public GoodsFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @return A new instance of fragment GoodsFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static GoodsFragment newInstance(String param1) {
        GoodsFragment fragment = new GoodsFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        ButterKnife.bind(this, getView(inflater, container));
        return getView(inflater, container);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_goods;
    }

    @Override
    public void initView(View baseView) {
        ButterKnife.bind(this, baseView);
        Gooods gooods = new Gooods();
        gooods.setUid(SPUserInfo.getUid(this.getContext()));
        gooods.setCategory(mParam1);
        trContent.setView(GoodsVH.class,mPresenter)
                .setParam("param",GsonUtils.getmGson().toJson(gooods))
                .fetch();
    }

    @Override
    public boolean isSwipeBack() {
        return false;
    }

    @Override
    public void initPresenter() {
        mPresenter.setVM(this, mModel, this._mActivity);

    }

    @Override
    public void finish() {
        _mActivity.onBackPressed();
    }
}
